<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * 内容模型
 */
class Article extends Model
{
    use SoftDeletes;
    protected $table = 'articles';

    protected $primaryKey = 'id';

    protected $fillable = [
                            'title',
                            'flag',
                            'thumb',
                            'slug',
                            'cid',
                            'description',
                            'content',
                        ];
    protected $hidden =[
        'deleted_at','updated_at','praise_num','is_video'
    ];

    protected $casts = [
    ];

    public function category()
    {
        //模型名 外键 本键
        return $this->hasOne('Xloong\Models\Category', 'id', 'cid');
    }

    public function user(){
        return $this->hasOne('App\Models\Member','id','user_id');
    }

    public function image(){
        return $this->belongsToMany('App\Models\Image','article_images');
    }
}
